﻿/***************************************************************/
mini.parse();
var tabs = mini.get("mainTabs");
var tree = mini.get("tree1");
tree.setUrl("Service/SystemManageHandler.ashx?action=LoadMenuList");
function showTab(node) {
    var tabs = mini.get("mainTabs");
    var id = "tab$" + node.MenuID;
    var tab = tabs.getTab(id);
    if (!tab) {
        tab = {};
        tab.name = id;
        tab.title = node.MenuName;
        tab.showCloseButton = true;
        tab.url = node.URL;
        tabs.addTab(tab);
    }
    tabs.activeTab(tab);
}

function onNodeSelect(e) {

    var node = e.node;
    var isLeaf = e.isLeaf;

    if (isLeaf) {
        showTab(node);
    }
}

function onBeforeExpand(e) {
    var tree = e.sender;
    var nowNode = e.node;
    var root = tree.getRootNode();

    tree.cascadeChild(root, function (node) {
        if (tree.isExpandedNode(node)) {
            if (node != nowNode && !tree.isAncestor(node, nowNode)) {
                tree.collapseNode(node, true);
            }
        }
    });
}
var currentTab = null;

function onBeforeOpen(e) {
    currentTab = tabs.getTabByEvent(e.htmlEvent);
    if (!currentTab) {
        e.cancel = true;
    }
}

function closeAllBut() {
    var but = [currentTab];
    but.push(tabs.getTab("first"));
    tabs.removeAll(but);
}



/****************************皮肤更换***********************************/
function onSkinChange(skin) {
    var skinEl = document.getElementById("miniuiSkin");
    if (skinEl) {
        skinEl.parentNode.removeChild(skinEl);
    }
    var url = "../lib/miniui/themes/" + skin + "/skin.css";
    AddCSSLink("miniuiSkin", url);
    setCookie("AndonSkin", skin, 24, "/");

    //处理demo iframe
    try {
        var win = document.getElementById("mainframe").contentWindow;
        var doc = win.document;
        var skinEl = doc.getElementById("miniuiSkin");
        if (skinEl) {
            skinEl.parentNode.removeChild(skinEl);
        }
        url = "../" + url;
        AddCSSLink("miniuiSkin", url, doc);

        if (win.mini) {
            win.mini.repaint();
        }
    }
    catch (e) {
    }
}
function AddCSSLink(id, url, doc) {
    doc = doc || document;
    var link = doc.createElement("link");
    link.id = id;
    link.setAttribute("rel", "stylesheet");
    link.setAttribute("type", "text/css");
    link.setAttribute("href", url);

    var heads = doc.getElementsByTagName("head");
    if (heads.length)
        heads[0].appendChild(link);
    else
        doc.documentElement.appendChild(link);
}

function switchuser() {
    mini.open({
        url: "CommonManage/ChangePwdMasterForm.aspx",
        title: "切换用户", width: 270, height: 165,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { action: "new" };
        },
        ondestroy: function (action) {
            //grid.reload();
        }
    });
}

function onExitClick() {
    mini.loading("系统退出中，请稍后...", "退出");
    setTimeout(function () {
        window.top.location = "../exit.aspx";
    }, 1500);
}